import useRequet, { RespData } from "../hook/network"
import { ElMessage } from 'element-plus'
import { Option } from '../types/index'

import { ref } from 'vue'

const request = useRequet({ path: "" });

// 得到医生
export const getDoctors = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'company/user/user/getDoctorListAll',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取医生' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取医生' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 得到咨询师

export const getConsultant = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'company/user/user/getConsultListAll',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取咨询师' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取咨询师' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 得到所有用户

export const getAllUser = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'company/user/user/getUserList',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取用户' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取用户' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 添加历史患者
export const addHistoryPerson = (id: number) => {
  return new Promise((resolve, reject) => {
    request.sendRequest({
      address: 'customer/info/addSelectLog',
      params: {
        customerId: id
      },
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('添加历史患者' || resp.msg)
        resolve(resp.data)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('添加历史患者获取用户' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "POST",
    })
  })
}

// 获取随访联系方式 下拉
export const getAccessLogContactType = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getAccessLogContactType',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取联系方式' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取联系方式' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 生成病历号
export const getCreateHistoryNum = () => {
  let list = ref('')

  return new Promise<number | string>((resolve, reject) => {
    request.sendRequest({
      address: 'customer/info/createHistoryNum',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('生成病历号' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('生成病历号' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 获取随访项目 下拉
export const getAccessFollowItem = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getAccessFollowItem',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访项目' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访项目' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}
// 获取随访内容 下拉
export const getAccessFollowContent = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getAccessFollowContent',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访内容' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访内容' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}

// 获取随访结果 下拉
export const getAccessFollowBackContent = () => {
  let list = ref([] as Option[])

  return new Promise<Option[]>((resolve, reject) => {
    request.sendRequest({
      address: 'sick/accessLog/getAccessFollowBackContent',
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访结果' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取随访结果' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}
